Skip to content

Sanitize the citation page and build the people committee lists safely - #60

Open
kf8a wants to merge 1 commit into
masterfrom
fix/sanitize-citation-people-views
Open

kf8a wants to merge 1 commit into
masterfrom
fix/sanitize-citation-people-views

Conversation

@kf8a

@kf8a kf8a commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Summary

Brakeman flagged 10 cross-site scripting warnings in the citation page and the people directory (one of them high confidence). This fixes all of them: Brakeman goes from 15 warnings to 5, with none new.

Citation page (citations/show.html.erb)

  • The citation text was printed with raw @citation.formatted(long: true), so markup in a title or journal name ran in the page. It now goes through sanitized_title, which keeps sub, sup, em, i, strong and b (no attributes) and removes everything else.
  • The publisher link was link_to ..., @citation.publisher_url, so a javascript: address in a record became a clickable script. A new CitationsHelper#web_url only allows http:// and https:// addresses; anything else shows no link.

People directory (people/index.html.erb)

  • PeopleHelper#show_committee built its <li> by string concatenation, and the view marked it safe with raw (8 calls). It now builds the list item with tag.li, safe_join and link_to, which escape the committee and the names, and the views drop raw. The output is the same for normal names.

Moved: sanitized_title and its tag list move from DatatablesHelper to ApplicationHelper, since citations use it too. The datatable pages are unchanged.

Not changed

Still flagged by Brakeman (5): the 3 accepted SQL warnings in datatable.rb (admin-written queries), raw(datatable.title_and_years) in datatables/_datatable.html.erb:13 and sponsors/index.html.erb:1. The citation abstract still goes through markdown_to_html with unsafe: true; Brakeman doesn't flag it, but it is the largest remaining raw-HTML path (audit finding 6) and needs a wider tag list than titles do.

Before merging

Citations whose titles or journal names deliberately contain other markup, such as links or line breaks, will lose it on the citation page. A quick check on production data:

SELECT id, title, publication FROM citations WHERE title ~ '<' OR publication ~ '<';

Testing

  • spec/requests/citation_people_markup_spec.rb: simple formatting stays and scripts and event handlers go from a citation title; a title like </script><script>alert(1)</script> can't break out of the page's JSON-LD data block; a javascript: publisher URL is not linked while an https:// one is; a person's name containing a script tag is escaped in the committee list, which still links to their page.
  • spec/helpers/citations_helper_spec.rb (web_url) and spec/helpers/people_helper_spec.rb (show_committee): current members only, escaping of names and the committee, safe output.
  • 7 of the 14 new examples fail against the old code.
  • Full suite: 339 examples, 0 failures, 3 pending. Brakeman 8.1.0 before and after.

Generated by Claude Code

Citation page: the citation text was printed with raw, so markup in a
title or journal name ran in the page. It now goes through sanitized_title,
which keeps sub, sup, em, i, strong and b and removes everything else. The
publisher link is only shown for http(s) addresses (web_url), so a
javascript: address in the record is no longer a link.

People directory: show_committee built its list item by string concatenation
and the view marked it html_safe with raw. It now builds safe HTML with
tag.li, safe_join and link_to, which escape the committee and names, and the
views drop raw.

sanitized_title moves from DatatablesHelper to ApplicationHelper, as it is
no longer only for datatables. Brakeman: 15 warnings down to 5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016AR3uoZS1uCC8hXmojk3K7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants